#ifndef CSYNCTCPSOCKET_H
#define CSYNCTCPSOCKET_H

#include <QTcpSocket>
#include <QTimer>
#include <QTime>
#include "aes/aestools.h"

class CSyncTcpSocket : public QTcpSocket
{
    Q_OBJECT
public:
    explicit CSyncTcpSocket(QObject *parent = 0);

    enum SockType{
        WebClient = 0x0,
        GateWay = 0x1,
        Control = 0x2
    };

    QString serial;
    SockType sockType;
    QTime _lastTimeRcv;
    bool _isGBK;

    void readyToWork();
    void setSocketType(SockType type);
    bool connectHostAndVerify(QString ip,int port,QString verifyMsg,QString ackMsg);
    void setEncryKey(QString key);
    bool appendSendData(QString smsg);
    void clearSendList();

    void sendData(QString msg);
    QString readData();

signals:
    void s_onceData(QString msg);
    void s_maybeDisconectFromHost();

public slots:
    void readReadyData();
    void doAlive();
    void doSendData();

private:

    QList<QString> _sendList;
    AESTools *_aes;

    QTimer _aliveTimer,_sendTimer;
};

#endif // CSYNCTCPSOCKET_H
